<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2.6.11"></script>
    <style>
        li {
            list-style: none;
            border: 1px dashed #999;
            margin: 5px;
            line-height: 35px;
            padding-left: 5px;
            font-size: 12px;
            width: 100%;
        }
        
        li:hover {
            background-color: pink;
            transition: all 0.8s ease;
        }
        
        .v-enter,
        .v-leave-to {
            opacity: 0;
            transform: translateY(80px);
        }
        
        .v-enter-active,
        .v-leave-active {
            transition: all 0.6s ease;
            position: absolute;
        }
        
        .v-move {
            transition: all 0.6s ease;
        }
    </style>
</head>

<body>
    <div id="app">
        <div>
            <label>
                Id:
                <input type="text" v-model="id">
            </label>
            <label>
                Name:
                <input type="text" v-model="name">
            </label>
            <input type="button" value="添加" @click="add">
        </div>

        <!-- <ul> -->
        <!-- 动画控制的需要元素如果是 v-for 需要用transition-group包裹 -->
        <transition-group appear tag="ul">
            <li v-for="(item , i) in list" :key="item.id" @click="del(i)">
                {{item.id}} --- {{item.name}}
            </li>
        </transition-group>
        <!-- </ul> -->
    </div>
    <script>
        var vm = new Vue({
            el: '#app',
            data: {
                id: '',
                name: '',
                list: [{
                    id: 1,
                    name: 'chengming'
                }, {
                    id: 2,
                    name: 'sky'
                }, {
                    id: 3,
                    name: 'heling'
                }]
            },
            methods: {
                add() {
                    this.list.push({
                        id: this.id,
                        name: this.name
                    })
                    this.id = ''
                    this.name = ''
                },
                del(i) {
                    this.list.splice(i, 1)
                }
            }
        });
    </script>
</body>

</html>